package com.jqb.hibernatebbs.service.impl;

import java.util.List;

import com.jqb.hibernatebbs.pojo.Bbsuser;
import com.jqb.hibernatebbs.service.UserService;
import com.jqb.hibernatebbs.util.SessionLazyHandler;

public class UserServiceImpl extends CommonServiceImpl implements UserService {
	/**
	 * 验证登录
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Bbsuser checkLogin(Bbsuser user) {
		String[] params = { user.getName(), user.getPassword() };
		String hql = "from Bbsuser where name=? and password=?";
		List<Bbsuser> list = (List<Bbsuser>) SessionLazyHandler.hqlQuery(hql, params);
		if (list.size() == 1) {
			user = list.get(0);
		} else {
			user = null;
		}
		return user;
	}

	@Override
	public Object getUserByName(String name) {
		Object obj = null;
		String hql = "from Bbsuser where name = ?";
		obj = SessionLazyHandler.hqlQueryByUniqueString(hql, name);
		return obj;
	}
}
